package LambdaTest;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class test {
    @FunctionalInterface
    interface NoParamNoReturn{
        void test();
    }

    @FunctionalInterface
    interface OneParamNoReturn{
        void test(int param);
    }

    @FunctionalInterface
    interface MoreParamNoReturn{
        void test(int x,int y);
    }

    @FunctionalInterface
    interface NoParamReturn{
        int test();
    }

    @FunctionalInterface
    interface OneParamReturn{
        int test(int param);
    }

    @FunctionalInterface
    interface MoreParamReturn{
        int test(int x,int y);
    }

    public static void main1(String[] args) {
        NoParamNoReturn noParamNoReturn = () ->{
                System.out.println("测试: "+NoParamNoReturn.class);
        };
        noParamNoReturn.test();

        OneParamNoReturn oneParamNoReturn = (param)-> {
                System.out.println("测试: "+OneParamReturn.class+" 参数:"+param);
        };
        oneParamNoReturn.test(7);

        MoreParamNoReturn moreParamNoReturn = (x,y) ->{
                System.out.println("测试: "+MoreParamNoReturn.class+" 参数:"+(x+y));
        };
        moreParamNoReturn.test(3,5);

        NoParamReturn noParamReturn =() ->{
                System.out.print("测试: "+NoParamReturn.class);
                return 1;
        };
        int ret1 = noParamReturn.test();
        System.out.println(ret1);

        OneParamReturn oneParamReturn = (param) ->{
                System.out.print("测试: "+OneParamReturn.class+" 参数: "+param);
                return 2;
        };
        int ret2=oneParamReturn.test(10);
        System.out.println(ret2);

        MoreParamReturn moreParamReturn = (x,y)-> {
                System.out.print("测试: "+MoreParamReturn.class+" 参数: "+(x+y));
                return 18;
        };
        int ret3 = moreParamReturn.test(5,7);
        System.out.println(ret3);
    }

    public static void main2(String[] args) {
        MoreParamNoReturn moreParamNoReturn = (x,y) -> {
                System.out.println("测试: "+MoreParamNoReturn.class+" 参数:"+(x+y));
        };
        moreParamNoReturn.test(3,5);

        OneParamNoReturn oneParamNoReturn = param-> {
            System.out.println("测试: "+OneParamReturn.class+" 参数:"+param);
        };
        oneParamNoReturn.test(7);

        NoParamNoReturn noParamNoReturn = () -> System.out.println("测试: "+NoParamNoReturn.class);
        noParamNoReturn.test();

        NoParamReturn noParamReturn =() -> 1;
        int ret1 = noParamReturn.test();
        System.out.println(ret1);
    }

    public static void main(String[] args) {
        NoParamNoReturn noParamNoReturn = () ->
        {
            int a = 100;
            System.out.println("测试: "+NoParamNoReturn.class);
            System.out.println("捕获的变量: "+a);
        };
        noParamNoReturn.test();
    }
}
